package com.lanou.dllo.soccernews.adapter;


import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.dllo.soccernews.R;
import com.lanou.dllo.soccernews.bean.CollectionBean;
import com.lanou.dllo.soccernews.bean.greendao.CollectionBeanArticlesEntity;
import com.lanou.dllo.soccernews.volley.GetVolleyDatasUtil;

import java.util.List;

/**
 * Created by dllo on 15/10/26.
 */
public class CollectionAdapter extends RecyclerView.Adapter<CollectionAdapter.MyViewHolder> {
    private List<CollectionBeanArticlesEntity> articlesEntities;

    public void addData(List<CollectionBeanArticlesEntity> articlesEntities) {
        this.articlesEntities = articlesEntities;
        notifyDataSetChanged();

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.item_circlerecycleview, null);

        return new MyViewHolder(view);
    }


    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        //设置参数
        if (articlesEntities != null && articlesEntities.size() > 0) {
            CollectionBeanArticlesEntity articles = articlesEntities.get(position);
            holder.co_content.setText(articles.getTitle());
            holder.co_comments_total.setText(articles.getComments_total() + "");

            if (articles.getThumb() != null && articles.getThumb().length() > 0) {
                String imgUrl = articles.getThumb();
                //   GetVolleyDatasUtil.getBitmapRequest(imgUrl, holder.co_thump);
                GetVolleyDatasUtil.getNetWorkImg(imgUrl, holder.co_thump);
            }

        }
    }

    @Override
    public int getItemCount() {
        return articlesEntities != null && articlesEntities.size() > 0 ? articlesEntities.size()
                : 0;
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView co_content, co_comments_total;

        private ImageView co_thump;

        public MyViewHolder(View itemView) {
            super(itemView);
            //初始化
            co_content = (TextView) itemView.findViewById(R.id.ci_content);

            co_comments_total = (TextView) itemView.findViewById(R.id.ci_comments_total);

            co_thump = (ImageView) itemView.findViewById(R.id.ci_thumb);


        }
    }
}
